<?php
/**
 * @Author: Wang chunsheng  email:2192138785@qq.com
 * @Date:   2020-05-16 13:45:08
 * @Last Modified by:   Wang chunsheng  email:2192138785@qq.com
 * @Last Modified time: 2020-05-16 13:46:31
 */
 

namespace common\addons\diandi_shop\models\searchs;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\addons\diandi_shop\models\DdShopAreas as DdShopAreasModel;

/**
 * DdShopAreas represents the model behind the search form of `app\modules\diandi_shop\models\DdShopAreas`.
 */
class DdShopAreas extends DdShopAreasModel
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['area_id','bloc_id','store_id', 'create_time', 'status', 'province_id', 'city_id', 'region_id'], 'integer'],
            [['area_name', 'address', 'logo'], 'safe'],
            [['freight'], 'number'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = DdShopAreasModel::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'area_id' => $this->area_id, 
            'bloc_id' => $this->bloc_id,
            'store_id' => $this->store_id,
            'create_time' => $this->create_time,
            'status' => $this->status,
            'freight' => $this->freight,
            'province_id' => $this->province_id,
            'city_id' => $this->city_id,
            'region_id' => $this->region_id,
        ]);

        $query->andFilterWhere(['like', 'area_name', $this->area_name])
            ->andFilterWhere(['like', 'address', $this->address])
            ->andFilterWhere(['like', 'logo', $this->logo]);

        return $dataProvider;
    }
}
